<template>
    <div>
      <h2>axios 测试页面</h2>
      <h3>{{ obj }}</h3>
      <button @click="send()">发送请求</button>
      <button @click="send2()">发送请求2</button>
      <button @click="send3()">发送请求3</button>
      <button @click="send4()">发送请求4</button>
      <button @click="send5()">发送请求5</button>
      <button @click="send6()">发送请求6</button>
    </div>
</template>

<script>
  import axios from 'axios';
  import httpRequest from '../../util/httpRequest';

  export default {
    name: 'axiosDemo',
    data() {
      return {
        obj: 'null'
      }
    },
    methods:  {
      send (){
        axios({
          type: 'get',
          url: '/cc/json/mobile_tel_segment.htm?tel=15105427721',
        }).then(({ data}) =>{
          console.log(data)
        },function (errrr) {
          console.log(errrr)
        }.bind(this)).catch(function (err) {
          console.log(err)
        } );
      },
      send2 (){
        axios({
          type: 'get',
          url: '/cc/json/mobile_tel_segment.htm',
          params:{
            tel: 15105427721
          }
        }).then(function (data) {
          console.log('22222222222')
          console.log(data.data)
        },function (errrr) {
          console.log(errrr)
        }.bind(this)).catch(function (err) {
          console.log(err)
        } );
      },
      send3 (){
         return axios.get('/cc/json/mobile_tel_segment.htm',{
          params:{
            tel: 15105427721
          }
        })
      },
      send4 (){
        axios.all([
            axios.get('/cc/json/mobile_tel_segment.htm',{
              params:{
                tel: 15105427721
              }
            }),
            this.send3()
        ]).then(results => {
          console.log('444444444444')
          console.log(results)
        });
      },
      send5 (){
        var p = Promise.all([
          new Promise((resolve, reject) => {
            axios.get('/cc/json/mobile_tel_segment.htm',{
              params:{
                tel: 15105427721
              }
            }).then(function (data) {
              resolve(data.data)
            },function (errrr) {
              resolve(errrr)
            })
          }),
          new Promise((resolve, reject) => {
            this.send3().then(function (data) {
              resolve(data.data)
            },function (errrr) {
              console.log(errrr)
            }.bind(this)).catch(function (err) {
              console.log(err)
            } );
          }),
        ])
        p.then(results => {
          console.log('5555555555')
          console.log(results)
        });
      },
      send6 (){
        httpRequest({
          type: 'get',
          url: '/cc/json/mobile_tel_segment.htm',
          params:{
            tel: 15105427721
          }
        })
          .then(
            (data) =>{
              console.log(data)
            }
          )
          .catch(
            (data) =>{
              console.log(data)
            }
          )
      }
    }
  }
</script>

<style scoped>

</style>
